package com.ljh.redis.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author: Themberfue
 * @date: 2025/4/5 15:17
 * @description:
 */
@RestController
public class StringController {
    @Autowired
    StringRedisTemplate redisTemplate;

    @GetMapping("/string")
    public String string() {
        // TODO 先清除数据库
        redisTemplate.execute((RedisConnection connection) -> {
            connection.flushAll();
            return null;
        });

        redisTemplate.opsForValue().set("k1", "111");
        Map<String, String> kv = Map.of("k2", "222", "k3", "333");
        redisTemplate.opsForValue().multiSet(kv);

        return redisTemplate.opsForValue().get("k1");
    }
}
